Location: pH control @ 494e3dc94373 / pH Homeostasis.nb

Author:
Randall Britten <r.britten@auckland.ac.nz>
Date:
2013-09-13 14:51:52+12:00
Desc:
Updated Mathematica to explore what equilibrium the textbook value of pK=6.1 gives compared to using the initial values read off Peter's slides. Change pK = pKbyInitial to pK = pKfromTextbook to see the difference: textbook value does not match initial conditions on slide being at equilibrium, and ODE runs to a pH of around 4.5!
Permanent Source URI:
https://models.physiomeproject.org/workspace/178/rawfile/494e3dc94373433a0bf3fdc7c37aaf20b64d095c/pH Homeostasis.nb

(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 9.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       157,          7]
NotebookDataLength[     10932,        310]
NotebookOptionsPosition[      9923,        276]
NotebookOutlinePosition[     10278,        292]
CellTagsIndexPosition[     10235,        289]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
 RowBox[{
  RowBox[{"initialPh", "=", "7.4"}], ";"}]], "Input",
 CellChangeTimes->{{3.588028935288416*^9, 3.588028947630732*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"initialHmolar", "=", 
   SuperscriptBox["10", 
    RowBox[{"-", "initialPh"}]]}], ";"}]], "Input",
 CellChangeTimes->{
  3.588026866945672*^9, 3.588027345006266*^9, {3.588027526578341*^9, 
   3.588027528457705*^9}, {3.5880275950477552`*^9, 3.588027623943098*^9}, {
   3.588028951319806*^9, 3.588028955827985*^9}, {3.588029035381466*^9, 
   3.5880290360526953`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"initialCO2mmHg", "=", "40"}], ";"}]], "Input",
 CellChangeTimes->{{3.588028961701105*^9, 3.5880289701902637`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"initialCO2molar", "=", 
   FractionBox["initialCO2mmHg", 
    RowBox[{"1000", " ", "s"}]]}], ";"}]], "Input",
 CellChangeTimes->{
  3.588026852226532*^9, 3.588026943288953*^9, {3.5880275452983923`*^9, 
   3.58802754682507*^9}, {3.588027627063496*^9, 3.588027635999963*^9}, {
   3.588028977886209*^9, 3.588029022197158*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"initialHCO3molar", "=", 
   FractionBox["25", "1000"]}], ";"}]], "Input",
 CellChangeTimes->{{3.588026722934659*^9, 3.588026782099729*^9}, {
  3.5880268336268*^9, 3.5880268489163713`*^9}, {3.588027568622901*^9, 
  3.58802758199266*^9}, {3.588027639231584*^9, 3.588027643926466*^9}, {
  3.588027675198184*^9, 3.588027680281584*^9}, {3.5880290081013393`*^9, 
  3.588029028437154*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"KbyInitial", "=", 
   FractionBox[
    RowBox[{"initialHmolar", " ", "initialHCO3molar"}], "initialCO2molar"]}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.5880276531793737`*^9, 3.5880276717256613`*^9}, {
   3.588027720485572*^9, 3.588027766262341*^9}, 3.588028516161331*^9, {
   3.588029040884555*^9, 3.5880290519690933`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"pKbyInitial", " ", "=", " ", 
   RowBox[{"-", 
    RowBox[{"Log10", "[", "KbyInitial", "]"}]}]}], ";"}]], "Input",
 CellChangeTimes->{{3.588027774043713*^9, 3.588027798668395*^9}, 
   3.588028524865922*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"pKfromTextbook", "=", "6.1"}], ";"}]], "Input",
 CellChangeTimes->{{3.588028556376622*^9, 3.58802856809615*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"pK", "=", "pKbyInitial"}], ";"}]], "Input",
 CellChangeTimes->{{3.588012091145185*^9, 3.588012101508132*^9}, {
  3.5880279392324457`*^9, 3.588027942287491*^9}, {3.588028238776577*^9, 
  3.588028273455275*^9}, {3.588028426076599*^9, 3.588028460818761*^9}, {
  3.5880285731120453`*^9, 3.5880286202728643`*^9}, {3.58802915260962*^9, 
  3.58802918097818*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"K", "=", 
   SuperscriptBox["10", 
    RowBox[{"-", "pK"}]]}], ";"}]], "Input",
 CellChangeTimes->{{3.588012103263454*^9, 3.588012122807251*^9}, 
   3.588012563011053*^9, 3.588029064612894*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"kb", "=", "1"}], ";"}]], "Input",
 CellChangeTimes->{{3.588010443656406*^9, 3.5880104461810017`*^9}, {
  3.588019520702352*^9, 3.5880195213259*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"kf", "=", 
   RowBox[{"K", " ", "kb"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.588010428890769*^9, 3.588010442109171*^9}, {
  3.588019524093988*^9, 3.588019525365821*^9}, {3.5880271611468267`*^9, 
  3.5880271626666107`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"solubilityMolarPerMmhg", "=", "0.03"}], ";"}]], "Input",
 CellChangeTimes->{{3.588011381426174*^9, 3.5880113944215317`*^9}, {
  3.588029074748098*^9, 3.588029092014204*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"pCO2", "[", 
    RowBox[{"apH_", ",", "aHCO3_"}], "]"}], ":=", 
   RowBox[{
    FractionBox[
     SuperscriptBox["10", 
      RowBox[{"-", "apH"}]], "K"], 
    FractionBox["aHCO3", "solubilityMolarPerMmhg"]}]}], ";"}]], "Input",
 CellChangeTimes->{{3.588011527879652*^9, 3.588011574290142*^9}, {
  3.588011605456628*^9, 3.588011648639924*^9}, {3.5880119395225277`*^9, 
  3.588011941657003*^9}, {3.588029099237656*^9, 3.588029102004583*^9}}],

Cell[BoxData[
 RowBox[{"ContourPlot", "[", 
  RowBox[{
   RowBox[{"pCO2", "[", 
    RowBox[{"pH", ",", "HCO3"}], "]"}], ",", 
   RowBox[{"{", 
    RowBox[{"pH", ",", "6.8", ",", "8"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"HCO3", ",", "0", ",", "100"}], "}"}]}], "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{",", "\[IndentingNewLine]", 
    RowBox[{"Contours", "\[Rule]", 
     RowBox[{"{", 
      RowBox[{"20", ",", "40", ",", "80"}], "}"}]}]}], "*)"}], 
  "\[IndentingNewLine]", "]"}]], "Input",
 CellChangeTimes->{{3.588011703454999*^9, 3.5880117174087048`*^9}, {
  3.5880117501903267`*^9, 3.588011883386302*^9}, {3.588012489020569*^9, 
  3.588012525930511*^9}, {3.58802796882439*^9, 3.5880279848488283`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"J", "[", 
    RowBox[{"CO2_", ",", "H_", ",", "HCO3_"}], "]"}], ":=", 
   RowBox[{
    RowBox[{"kf", " ", "CO2"}], "-", 
    RowBox[{"kb", " ", "H", " ", "HCO3"}]}]}], ";"}]], "Input",
 CellChangeTimes->{{3.588018786296715*^9, 3.588018834936934*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"s1", "=", 
   RowBox[{"NDSolve", "[", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"{", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{
        RowBox[{
         RowBox[{"H", "'"}], "[", "t", "]"}], "\[Equal]", 
        RowBox[{"J", "[", 
         RowBox[{
          RowBox[{"CO2", "[", "t", "]"}], ",", 
          RowBox[{"H", "[", "t", "]"}], ",", 
          RowBox[{"HCO3", "[", "t", "]"}]}], "]"}]}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{
         RowBox[{"HCO3", "'"}], "[", "t", "]"}], "==", 
        RowBox[{"J", "[", 
         RowBox[{
          RowBox[{"CO2", "[", "t", "]"}], ",", 
          RowBox[{"H", "[", "t", "]"}], ",", 
          RowBox[{"HCO3", "[", "t", "]"}]}], "]"}]}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{
         RowBox[{"CO2", "'"}], "[", "t", "]"}], "\[Equal]", "0"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"H", "[", "0", "]"}], "\[Equal]", "initialHmolar"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"CO2", "[", "0", "]"}], "\[Equal]", "initialCO2molar"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"HCO3", "[", "0", "]"}], "\[Equal]", "initialHCO3molar"}]}], 
      "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", 
     RowBox[{"{", 
      RowBox[{"H", ",", "HCO3", ",", "CO2"}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{"t", ",", "0", ",", "100"}], "}"}]}], "]"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.588018715475564*^9, 3.5880187162902117`*^9}, {
   3.588018840234191*^9, 3.588018998732294*^9}, {3.588019038114986*^9, 
   3.5880191392578297`*^9}, {3.58801919229058*^9, 3.5880192037189703`*^9}, {
   3.5880192708295116`*^9, 3.5880193124369717`*^9}, 3.588019393691187*^9, {
   3.588019780866252*^9, 3.588019781165984*^9}, {3.5880267892763033`*^9, 
   3.588026813484517*^9}, {3.588027037873416*^9, 3.5880270428576*^9}, {
   3.588027279146137*^9, 3.588027321720139*^9}, {3.5880273575433826`*^9, 
   3.5880273907936583`*^9}, {3.588027420862603*^9, 3.5880274750777607`*^9}, {
   3.5880280434626217`*^9, 3.5880280573032427`*^9}, {3.5880291201567917`*^9, 
   3.588029129520361*^9}}],

Cell[BoxData[
 RowBox[{"Plot", "[", 
  RowBox[{
   RowBox[{"Evaluate", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"-", 
       RowBox[{"Log10", "[", 
        RowBox[{"H", "[", "t", "]"}], "]"}]}], 
      RowBox[{"(*", 
       RowBox[{"1000", " ", "s", " ", 
        RowBox[{"CO2", "[", "t", "]"}]}], "*)"}], "}"}], "/.", "s1"}], "]"}], 
   ",", 
   RowBox[{"{", 
    RowBox[{"t", ",", "0", ",", "100"}], "}"}], ",", 
   RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]], "Input",
 CellChangeTimes->{{3.5880193595553627`*^9, 3.588019419808826*^9}, {
  3.588019586814019*^9, 3.588019640555421*^9}, {3.588019692218618*^9, 
  3.588019694042286*^9}, {3.588019750250059*^9, 3.588019813783346*^9}}],

Cell[BoxData[
 RowBox[{"Plot", "[", 
  RowBox[{
   RowBox[{"Evaluate", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"1000", " ", "s", " ", 
       RowBox[{"CO2", "[", "t", "]"}]}], "}"}], "/.", "s1"}], "]"}], ",", 
   RowBox[{"{", 
    RowBox[{"t", ",", "0", ",", "100"}], "}"}], ",", 
   RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]], "Input",
 CellChangeTimes->{{3.5880193595553627`*^9, 3.588019419808826*^9}, {
  3.588019586814019*^9, 3.588019640555421*^9}, {3.588019692218618*^9, 
  3.588019694042286*^9}, {3.588019750250059*^9, 3.58801983773449*^9}}],

Cell[BoxData[
 RowBox[{"Plot", "[", 
  RowBox[{
   RowBox[{"Evaluate", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"1000", " ", 
       RowBox[{"HCO3", "[", "t", "]"}]}], "}"}], "/.", "s1"}], "]"}], ",", 
   RowBox[{"{", 
    RowBox[{"t", ",", "0", ",", "100"}], "}"}], ",", 
   RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]], "Input",
 CellChangeTimes->{{3.5880193595553627`*^9, 3.588019419808826*^9}, {
  3.588019586814019*^9, 3.588019640555421*^9}, {3.588019692218618*^9, 
  3.588019694042286*^9}, {3.588019750250059*^9, 3.5880198711418*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"pHn", "[", "HCO3_", "]"}], ":=", 
  RowBox[{"6.1", "+", 
   RowBox[{"Log10", "[", 
    FractionBox["HCO3", 
     RowBox[{"s", " ", "40"}]], "]"}]}]}]], "Input",
 CellChangeTimes->{{3.5880288431502542`*^9, 3.588028918119533*^9}}]
},
WindowSize->{1440, 852},
WindowMargins->{{0, Automatic}, {Automatic, 0}},
FrontEndVersion->"9.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (January 25, \
2013)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[557, 20, 143, 3, 28, "Input"],
Cell[703, 25, 400, 9, 33, "Input"],
Cell[1106, 36, 149, 3, 28, "Input"],
Cell[1258, 41, 358, 8, 49, "Input"],
Cell[1619, 51, 417, 8, 49, "Input"],
Cell[2039, 61, 361, 8, 49, "Input"],
Cell[2403, 71, 241, 6, 28, "Input"],
Cell[2647, 79, 147, 3, 28, "Input"],
Cell[2797, 84, 390, 7, 28, "Input"],
Cell[3190, 93, 228, 6, 32, "Input"],
Cell[3421, 101, 183, 4, 28, "Input"],
Cell[3607, 107, 261, 6, 28, "Input"],
Cell[3871, 115, 208, 4, 28, "Input"],
Cell[4082, 121, 487, 12, 53, "Input"],
Cell[4572, 135, 724, 17, 80, "Input"],
Cell[5299, 154, 297, 8, 28, "Input"],
Cell[5599, 164, 2223, 51, 182, "Input"],
Cell[7825, 217, 700, 18, 28, "Input"],
Cell[8528, 237, 566, 13, 28, "Input"],
Cell[9097, 252, 556, 13, 28, "Input"],
Cell[9656, 267, 263, 7, 49, "Input"]
}
]
*)

(* End of internal cache information *)